﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ClientMappingTests.cs" company="Concept Architecture">
//   (c) 2010 Muhammad Umer Farooq
// </copyright>
// <summary>
//   Defines the ClientMappingTests type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Hisaab.Client.Test
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using AutoMapper;
    using Business.Entities;
    using Common;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Windows.Client;

    /// <summary>
    /// Defines the <seealso cref="ClientMappingTests"/> type.
    /// </summary>
    [TestClass]
    public class ClientMappingTests
    {
        /// <summary>
        /// Initializes this instance.
        /// </summary>
        /// <param name="context">The context.</param>
        [AssemblyInitialize]
        public static void Initialize(TestContext context)
        {
            ObjectMapper.AddProfile(new ClientMapping());
            Mapper.AssertConfigurationIsValid();
        }

        /// <summary>
        /// Mappings the should map account from Model entities.
        /// </summary>
        [TestMethod]
        public void MappingShouldMapAccountFromModelEntities()
        {
            var modelEntity = new Windows.Client.Model.Account
                                  {
                                      AccountType = 8,
                                      AccountId = 3,
                                      Name = "Account Name",
                                      InitialBalance = 345.54M,
                                      InitialBalanceDate = DateTime.Now
                                  };
            var businessEntity = modelEntity.Map<Windows.Client.Model.Account, Account>();

            Assert.AreEqual(modelEntity.AccountId, businessEntity.AccountId);
            Assert.AreEqual(modelEntity.AccountType, businessEntity.AccountType);
            Assert.AreEqual(modelEntity.Name, businessEntity.Name);
            Assert.AreEqual(modelEntity.InitialBalance, businessEntity.InitialBalance);
            Assert.AreEqual(modelEntity.InitialBalanceDate, businessEntity.InitialBalanceDate);
        }

        /// <summary>
        /// Mappings the should map account from business entities.
        /// </summary>
        [TestMethod]
        public void MappingShouldMapAccountFromBusinessEntities()
        {
            var businessEntity = new Account
            {
                AccountType = 4,
                AccountId = 3,
                Name = "Account Name"
            };
            var modelEntity = businessEntity.Map<Account, Windows.Client.Model.Account>();

            Assert.AreEqual(businessEntity.AccountId, modelEntity.AccountId);
            Assert.AreEqual(businessEntity.AccountType, modelEntity.AccountType);
            Assert.AreEqual(businessEntity.Name, modelEntity.Name);
            Assert.AreEqual(businessEntity.InitialBalance, modelEntity.InitialBalance);
            Assert.AreEqual(businessEntity.InitialBalanceDate, modelEntity.InitialBalanceDate);
        }

        /// <summary>
        /// Mappings the should map tag from Model entities.
        /// </summary>
        [TestMethod]
        public void MappingShouldMapAccountTypeFromModelEntities()
        {
            var modelEntity = new Windows.Client.Model.AccountType
            {
                Id = 3,
                Name = "AccountType Name"
            };
            var businessEntity = modelEntity.Map<Windows.Client.Model.AccountType, AccountType>();

            Assert.AreEqual(modelEntity.Id, businessEntity.Id);
            Assert.AreEqual(modelEntity.Name, businessEntity.Name);
        }

        /// <summary>
        /// Mappings the should map tag from business entities.
        /// </summary>
        [TestMethod]
        public void MappingShouldMapAccountTypeFromBusinessEntities()
        {
            var businessEntity = new AccountType
            {
                Id = 3,
                Name = "Account Name"
            };
            var modelEntity = businessEntity.Map<AccountType, Windows.Client.Model.AccountType>();

            Assert.AreEqual(businessEntity.Id, modelEntity.Id);
            Assert.AreEqual(businessEntity.Name, modelEntity.Name);
        }

        /// <summary>
        /// Mappings the should map tag from Model entities.
        /// </summary>
        [TestMethod]
        public void MappingShouldMapTagFromModelEntities()
        {
            var modelEntity = new Windows.Client.Model.Tag
            {
                TagId = 3,
                Name = "Tag Name"
            };
            var businessEntity = modelEntity.Map<Windows.Client.Model.Tag, Tag>();

            Assert.AreEqual(modelEntity.TagId, businessEntity.TagId);
            Assert.AreEqual(modelEntity.Name, businessEntity.Name);
        }

        /// <summary>
        /// Mappings the should map tag from business entities.
        /// </summary>
        [TestMethod]
        public void MappingShouldMapTagFromBusinessEntities()
        {
            var businessEntity = new Tag
            {
                TagId = 3,
                Name = "Account Name"
            };
            var modelEntity = businessEntity.Map<Tag, Windows.Client.Model.Tag>();

            Assert.AreEqual(businessEntity.TagId, modelEntity.TagId);
            Assert.AreEqual(businessEntity.Name, modelEntity.Name);
        }

        /// <summary>
        /// Mappings the should map transaction from Model entities.
        /// </summary>
        [TestMethod]
        public void MappingShouldMapTransactionFromModelEntities()
        {
            var modelEntity = new Windows.Client.Model.Transaction
                                  {
                                      TransactionId = 3,
                                      Title = "Transaction 1",
                                      Details = "bought some stuff",
                                      Account = 45,
                                      Amount = 4.56M,
                                      Date = DateTime.Now,
                                      TransactionType = Windows.Client.Model.TransactionTypes.Expanse,
                                      Tags = new List<Windows.Client.Model.Tag>
                                                 {
                                                     new Windows.Client.Model.Tag { Name = "Tag1" },
                                                     new Windows.Client.Model.Tag { Name = "Tag2" }
                                                 }
                                  };
            var businessEntity = modelEntity.Map<Windows.Client.Model.Transaction, Transaction>();

            Assert.AreEqual(modelEntity.TransactionId, businessEntity.TransactionId);
            Assert.AreEqual(modelEntity.Title, businessEntity.Title);
            Assert.AreEqual(modelEntity.Details, businessEntity.Details);
            Assert.AreEqual(modelEntity.Account, businessEntity.Account);
            Assert.AreEqual(modelEntity.Date, businessEntity.Date);
            Assert.AreEqual((int)modelEntity.TransactionType, (int)businessEntity.TransactionType);
            Assert.AreEqual(modelEntity.Tags.Count(), businessEntity.Tags.Count());
            Assert.AreEqual(modelEntity.Tags.ElementAt(0).TagId, businessEntity.Tags.ElementAt(0).TagId);
            Assert.AreEqual(modelEntity.Tags.ElementAt(0).Name, businessEntity.Tags.ElementAt(0).Name);
            Assert.AreEqual(modelEntity.Tags.ElementAt(1).TagId, businessEntity.Tags.ElementAt(1).TagId);
            Assert.AreEqual(modelEntity.Tags.ElementAt(1).Name, businessEntity.Tags.ElementAt(1).Name);
        }

        /// <summary>
        /// Mappings the should map transaction from business entities.
        /// </summary>
        [TestMethod]
        public void MappingShouldMapTransactionFromBusinessEntities()
        {
            var businessEntity = new Transaction
                                     {
                                         TransactionId = 3,
                                         Title = "Transaction 1",
                                         Details = "bought some stuff",
                                         Account = 45,
                                         Amount = 4.56M,
                                         Date = DateTime.Now,
                                         TransactionType = TransactionTypes.Expanse,
                                         Tags = new List<Tag>
                                                    {
                                                        new Tag { Name = "Tag1" },
                                                        new Tag { Name = "Tag2" }
                                                    }
                                     };
            var modelEntity = businessEntity.Map<Transaction, Windows.Client.Model.Transaction>();

            Assert.AreEqual(businessEntity.TransactionId, modelEntity.TransactionId);
            Assert.AreEqual(businessEntity.Title, modelEntity.Title);
            Assert.AreEqual(businessEntity.Details, modelEntity.Details);
            Assert.AreEqual(businessEntity.Account, modelEntity.Account);
            Assert.AreEqual(businessEntity.Date, modelEntity.Date);
            Assert.AreEqual((int)businessEntity.TransactionType, (int)modelEntity.TransactionType);
            Assert.AreEqual(businessEntity.Tags.Count(), modelEntity.Tags.Count());
            Assert.AreEqual(businessEntity.Tags.ElementAt(0).TagId, modelEntity.Tags.ElementAt(0).TagId);
            Assert.AreEqual(businessEntity.Tags.ElementAt(0).Name, modelEntity.Tags.ElementAt(0).Name);
            Assert.AreEqual(businessEntity.Tags.ElementAt(1).TagId, modelEntity.Tags.ElementAt(1).TagId);
            Assert.AreEqual(businessEntity.Tags.ElementAt(1).Name, modelEntity.Tags.ElementAt(1).Name);
        }

        /// <summary>
        /// Mappings the should map vehicle transaction from Model entities.
        /// </summary>
        [TestMethod]
        public void MappingShouldMapVehicleTransactionFromModelEntities()
        {
            var modelEntity = new Windows.Client.Model.VehicleTransaction
            {
                Id = 3,
                Fill = 4.56M,
                Milage = 100987,
                Oil = 34.55M,
                Service = 34.45M,
                Date = DateTime.Today.AddDays(-34),
                Notes = "This is some random note",
                Tires = 103.44M,
                Account = 34,
                VehicleId = 344,
                TransactionId = 43
            };
            var businessEntity = modelEntity.Map<Windows.Client.Model.VehicleTransaction, VehicleTransaction>();

            Assert.AreEqual(modelEntity.Id, businessEntity.Id);
            Assert.AreEqual(modelEntity.Fill, businessEntity.Fill);
            Assert.AreEqual(modelEntity.Date, businessEntity.Date);
            Assert.AreEqual(businessEntity.Notes, modelEntity.Notes);
            Assert.AreEqual(modelEntity.Milage, businessEntity.Milage);
            Assert.AreEqual(modelEntity.Oil, businessEntity.Oil);
            Assert.AreEqual(modelEntity.Service, businessEntity.Service);
            Assert.AreEqual(modelEntity.Tires, businessEntity.Tires);
            Assert.AreEqual(modelEntity.VehicleId, businessEntity.VehicleId);
            Assert.AreEqual(modelEntity.Account, businessEntity.Account);
            Assert.AreEqual(modelEntity.TransactionId, businessEntity.TransactionId);
        }

        /// <summary>
        /// Mappings the should map vehicle transaction from business entities.
        /// </summary>
        [TestMethod]
        public void MappingShouldMapVehicleTransactionFromBusinessEntities()
        {
            var businessEntity = new VehicleTransaction
            {
                Id = 3,
                Fill = 4.56M,
                Milage = 100987,
                Date = DateTime.Today.AddDays(-34),
                Notes = "This is another random note",
                Oil = 34.55M,
                Service = 34.45M,
                Tires = 103.44M,
                Account = 341,
                VehicleId = 344,
                TransactionId = 43
            };
            var modelEntity = businessEntity.Map<VehicleTransaction, Windows.Client.Model.VehicleTransaction>();

            Assert.AreEqual(businessEntity.Id, modelEntity.Id);
            Assert.AreEqual(businessEntity.Fill, modelEntity.Fill);
            Assert.AreEqual(businessEntity.Date, modelEntity.Date);
            Assert.AreEqual(businessEntity.Notes, modelEntity.Notes);
            Assert.AreEqual(businessEntity.Milage, modelEntity.Milage);
            Assert.AreEqual(businessEntity.Oil, modelEntity.Oil);
            Assert.AreEqual(businessEntity.Service, modelEntity.Service);
            Assert.AreEqual(businessEntity.Tires, modelEntity.Tires);
            Assert.AreEqual(businessEntity.VehicleId, modelEntity.VehicleId);
            Assert.AreEqual(businessEntity.Account, modelEntity.Account);
            Assert.AreEqual(businessEntity.TransactionId, modelEntity.TransactionId);
        }
    }
}